package com.ssm.admin.controller;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.ssm.admin.entity.SsmGoodsEntity;
import com.ssm.admin.service.SsmGoodsService;
import com.ssm.common.utils.PageUtils;
import com.ssm.common.utils.R;



/**
 * 
 *
 * @author ssm
 * @email sunlightcs@gmail.com
 * @date 2023-03-19 17:30:08
 */
@RestController
@RequestMapping("admin/ssmgoods")
public class SsmGoodsController {
    @Autowired
    private SsmGoodsService ssmGoodsService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = ssmGoodsService.queryPage(params);

        return R.ok().put("page", page);
    }
    @RequestMapping("list2")
    private R list2(@RequestParam Map<String,String> params){
        String key = params.get("key");
        if (key != null && key != "" ) {

            ArrayList<SsmGoodsEntity> entities = ssmGoodsService.select(key);
            return R.ok().put("entities",entities);
        }else {
            List<SsmGoodsEntity> list = ssmGoodsService.list();
            return R.ok().put("list",list);
        }

    }

    /**
     * 信息
     */
    @RequestMapping("/info/{goodsId}")
    public R info(@PathVariable("goodsId") Integer goodsId){
		SsmGoodsEntity ssmGoods = ssmGoodsService.getById(goodsId);

        return R.ok().put("ssmGoods", ssmGoods);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody SsmGoodsEntity ssmGoods){
		ssmGoodsService.save(ssmGoods);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody SsmGoodsEntity ssmGoods){
		ssmGoodsService.updateById(ssmGoods);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Integer[] goodsIds){
		ssmGoodsService.removeByIds(Arrays.asList(goodsIds));

        return R.ok();
    }

}
